<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>抚乐酒吧</title>
    <link rel="shortcut icon" href="../favicon.ico">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../styles/common.css"/>
    <link rel="stylesheet" href="../styles/index.css"/>
    <link rel="stylesheet" href="../styles/icon/iconfont.css"/>
    <style>
        .body {
            min-width: 1366px;
        }

        .carousel-btn {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            z-index: 100;
            background-color: rgba(0, 0, 0, 0.3);
            color: white;
            border: none;
            font-size: 24px;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            cursor: pointer;
            pointer-events: auto;
        }

        .prev-btn {
            left: 20px;
        }

        .next-btn {
            right: 20px;
        }

        .app-bgScrolling-main {
            height: 100vh;
            width: 100vw;
            position: fixed;
            top: 0;
            left: 0;
            z-index: 0;
        }

        .app-bgScrolling-main .divTmp {
            width: 100%;
            height: 100%;
        }

        .home-button {
            position: fixed;
            top: 20px;
            left: 20px;
            z-index: 999;
        }

        .lyrics-container {
            position: fixed;
            left: 50%;
            top: 0;
            height: 100vh;
            width: 95vw;
            overflow: hidden;
            z-index: 100;
            color: white;
            font-size: 36px;
            text-align: center;
            display: flex;
            align-items: center;
            justify-content: center;
            transform: translateX(-50%);
        }

        .speed-control {
            position: fixed;
            top: 80px;
            left: 20px;
            z-index: 101;
            width: 300px;
            background: rgba(0, 0, 0, 0.5);
            padding: 10px;
            border-radius: 5px;
            color: white;
        }

        @font-face {
            font-family: 'XingShu';
            src: url('../plugins/element-ui/fonts/element-icons.ttf') format('truetype');
        }

        @font-face {
            font-family: 'ZiKuXingQiuFeiYangTi';
            src: url('../plugins/font/ZiKuXingQiuFeiYangTi-2.ttf') format('truetype');
        }

        @font-face {
            font-family: 'MengshenHandwritten';
            src: url('../plugins/font/Mengshen-Handwritten-2.ttf') format('truetype');
        }

        @font-face {
            font-family: 'YiShanBeiZhuanTi';
            src: url('../plugins/font/YiShanBeiZhuanTi.ttf') format('truetype');
        }

        @font-face {
            font-family: 'YunFengFeiYunTi';
            src: url('../plugins/font/YunFengFeiYunTi-2.ttf') format('truetype');
        }

        @font-face {
            font-family: 'HuangKaiHuaLawyerFont';
            src: url('../plugins/font/huangkaihuaLawyerfont-2.ttf') format('truetype');
        }

        .lyrics-content {
            animation: scrollLyrics var(--scrollDuration) linear infinite;
            font-family: var(--lyricFont), cursive;
            color: var(--lyricColor);
            font-size: var(--lyricFontSize);
            list-style: none;
            padding: 0;
            margin: 0;
            position: relative;
        }

        .lyrics-content li {
            margin: var(--lineSpacing, 122px) 0;
            transition: font-weight 0.3s ease;
            font-weight: var(--lyricBold, normal);
            font-style: var(--lyricItalic, normal);
        }

        .lyrics-content li.active {
            font-weight: bold;
        }

        .lyrics-content li.active {
            font-weight: bold;
        }

        @keyframes scrollLyrics {
            0% {
                transform: translateY(0%);
            }
            100% {
                transform: translateY(50%);
            }
        }

        .lyrics-content {
            animation: scrollLyrics var(--scrollDuration) linear infinite;
            position: relative;
            animation-fill-mode: forwards;
        }

        .lyrics-content::before {
            content: '';
            display: block;
            height: 100%;
            position: absolute;
            top: -100%;
            left: 0;
            right: 0;
        }

        .lyrics-content::after {
            content: '';
            display: block;
            height: 100%;
            position: absolute;
            top: 100%;
            left: 0;
            right: 0;
        }


        .font-choose {
            display: flex;
            flex-wrap: nowrap;
        }
    </style>
</head>

<body>
<div class="app-bgScrolling" id="app-bgScrolling">
    <el-button type="primary" class="home-button" @click="goToHome" v-show="showHomeButton">返回首页</el-button>
    <div class="app-bgScrolling-main">
        <el-carousel :interval="carouselSpeed" height="100vh" ref="carousel" :autoplay="carouselSpeed > 0">
            <el-carousel-item v-for="item in carouselItems" :key="item.id">
                <img :src="item.url" style="width:100%;height:100%;object-fit:cover;">
            </el-carousel-item>
        </el-carousel>

    </div>
    <div class="lyrics-container">
        <ul class="lyrics-content">
            <li v-for="(lyric, index) in lyricsList" :key="index">{{ lyric }}</li>
        </ul>
    </div>
    <div class="speed-control" v-show="showHomeButton">
        <div style="color: white; margin: 10px 0 5px 0;">ID查询：</div>
        <div style="color: white; margin-bottom: 5px; display: flex; align-items: center; gap: 10px;">
            <el-input v-model="searchId" placeholder="输入段落ID" style="flex: 1;"></el-input>
            <el-button type="primary" @click="searchById">展示</el-button>
        </div>
        <div style="color: white; margin: 10px 0 5px 0;">滚动速度：</div>
        <el-slider v-model="scrollSpeed" :min="0" :max="17" :step="1"></el-slider>
        <div style="color: white; margin: 10px 0 5px 0;">字体大小：</div>
        <el-slider v-model="fontSize" :min="3" :max="15" :step="1"></el-slider>
        <div style="color: white; margin: 10px 0 5px 0;">行间距：</div>
        <el-slider v-model="lineSpacing" :min="50" :max="300" :step="2"></el-slider>
        <div style="color: white; margin: 10px 0 5px 0;">背景切换（分钟）：</div>
        <el-slider v-model="carouselSpeedMin" :min="0" :max="30" :step="1"></el-slider>
        <div style="color: white; margin: 10px 0 5px 0;">字体选择：</div>
        <el-select v-model="selectedFont" placeholder="选择字体">
            <el-option
                    v-for="font in fontOptions"
                    :key="font.value"
                    :label="font.label"
                    :value="font.value">
            </el-option>
        </el-select>

        <div class="font-choose">
            <div>
                <div style="color: white; margin: 10px 0 5px 0;">颜色选择：</div>
                <el-color-picker v-model="lyricColor" show-alpha></el-color-picker>
            </div>
            <div style="margin-left: 20px;">
                <div style="color: white; margin: 10px 0 5px 0;">字体样式：</div>
                <el-button @click="toggleBold" :type="isBold ? 'primary' : ''">加粗</el-button>
                <el-button @click="toggleItalic" :type="isItalic ? 'primary' : ''">倾斜</el-button>
            </div>
        </div>
    </div>

</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../plugins/axios/axios.min.js"></script>
<script src="../js/request.js"></script>
<script src="../api/manage.js"></script>
<script>
    new Vue({
        el: '#app-bgScrolling',
        data() {
            return {
                carouselItems: [],
                lyricsList: [],
                originalLyrics: [],
                showHomeButton: true,
                mouseTimer: null,
                scrollSpeed: 6,
                selectedFont: 'XingShu',
                lyricColor: 'rgba(255, 255, 255, 1)',
                fontSize: 4,
                lineSpacing: 122,
                isBold: false,
                isItalic: false,
                searchId: '',
                carouselSpeed: 600000,
                carouselSpeedMin: 10,
                fontOptions: [
                    {value: 'SimSun', label: '宋体'},
                    {value: 'XingShu', label: '行书'},
                    {value: 'SimHei', label: '黑体'},
                    {value: 'ZiKuXingQiuFeiYangTi', label: '字酷星球飞扬体'},
                    {value: 'MengshenHandwritten', label: '萌神手写体'},
                    {value: 'YiShanBeiZhuanTi', label: '义山碑篆体'},
                    {value: 'YunFengFeiYunTi', label: '云峰飞云体'},
                    {value: 'HuangKaiHuaLawyerFont', label: '黄凯华律师体'}
                ],
                updateScrollDuration: function () {
                    document.documentElement.style.setProperty('--scrollDuration', this.scrollDuration);
                }
            }
        },
        computed: {
            scrollDuration() {
                return `${1800 - this.scrollSpeed * 100}s`;
            }
        },
        created() {
            this.initData()
        },
        beforeDestroy() {
            if (this.timer) {
                clearInterval(this.timer);
            }
        },
        mounted() {
            this.setupMouseListeners();
            this.$watch('scrollSpeed', this.updateScrollDuration);
            this.$watch('selectedFont', function (newVal) {
                document.documentElement.style.setProperty('--lyricFont', newVal);
            });
            this.$watch('lyricColor', function (newVal) {
                document.documentElement.style.setProperty('--lyricColor', newVal);
            });
            this.$watch('fontSize', function (newVal) {
                document.documentElement.style.setProperty('--lyricFontSize', newVal + 'rem');
            });
            this.$watch('isBold', function (newVal) {
                document.documentElement.style.setProperty('--lyricBold', newVal ? 'bold' : 'normal');
            });
            this.$watch('isItalic', function (newVal) {
                document.documentElement.style.setProperty('--lyricItalic', newVal ? 'italic' : 'normal');
            });
            this.$watch('lineSpacing', function (newVal) {
                document.documentElement.style.setProperty('--lineSpacing', newVal + 'px');
            });
            this.$watch('carouselSpeedMin', this.transMsToMin);
            this.updateScrollDuration();
            document.documentElement.style.setProperty('--lyricFont', this.selectedFont);
            document.documentElement.style.setProperty('--lyricFontSize', this.fontSize + 'rem');
        },
        methods: {
            toggleBold() {
                this.isBold = !this.isBold;
            },
            toggleItalic() {
                this.isItalic = !this.isItalic;
            },
            prevSlide() {
                this.$refs.carousel.prev();
            },
            nextSlide() {
                this.$refs.carousel.next();
            },
            setupMouseListeners() {
                document.addEventListener('mousemove', () => {
                    this.showHomeButton = true;
                    if (this.mouseTimer) {
                        clearTimeout(this.mouseTimer);
                    }
                    this.mouseTimer = setTimeout(() => {
                        this.showHomeButton = false;
                    }, 3000);
                });
            },
            goToHome() {
                window.location.href = '../index.html';
            },
            initData() {
                getImageList().then(res => {
                    res = res.data;
                    if (res.code === 1) {
                        this.carouselItems = res.data.map(item => {
                            return {
                                id: item.id,
                                url: this.getImage(item.image)
                            }
                        });
                    }
                });

                getScrollingList({type: 0}).then(res => {
                    res = res.data;
                    if (res.code === 1) {
                        this.lyricsList = res.data.map(item => item.content);
                        this.originalLyrics = res.data;
                    }
                })

            },
            getImage(image) {
                return `/common/download?name=${image}`
            },
            searchById() {
                if (!this.searchId) {
                    this.lyricsList = this.originalLyrics.map(item => item.content);
                    return;
                }
                getScrollingById({id: this.searchId}).then(res => {
                    res = res.data;
                    if (res.code === 1) {
                        this.lyricsList = res.data.map(item => item.content);
                    } else {
                        this.$message.error(res.msg || '未找到对应ID的段落，请确认输入的ID是否正确');
                    }
                }).catch(() => {
                    this.$message.error('请求失败，请稍后重试');
                });
            },
            // 将毫秒转为分钟
            transMsToMin(){
                this.carouselSpeed = this.carouselSpeedMin * 60000;
            }
        }
    })
</script>
</body>
</html>
